package top.bfylu.singleton.chocolate;

/**
 * 包名: top.bfylu.singleton.chocolate
 * 创建时间: 2022/1/29
 *
 * @author bfy
 * @version 1.0.0
 * <p>
 * 描述: 巧克力锅炉单件
 * @Email bfyjian@gmail.com
 **/
public class ChocolateBoiler {
    private boolean empty;
    private boolean boiled;
    private static ChocolateBoiler uniqueInstance;
    //代码开始时，锅炉是空的
    public ChocolateBoiler() {
        empty = true;
        boiled = false;
    }

    public static synchronized ChocolateBoiler getInstance() {
        if (uniqueInstance == null) {
            uniqueInstance = new ChocolateBoiler();
        }
        return uniqueInstance;
    }

    //在锅炉内填入原料是，锅炉必须是空的，一空填入原料，就把empty和boiled标志设置好
    public void fill() {
        if (isEmpty()) {
            empty = false;
            boiled = false;
            //在锅炉内填满巧克力和牛奶的混合物
        }
    }

    //锅炉排出是，必须是满的（不可以是空的）而且是煮过的。排出完毕后，把empty标志设置true
    public void drain() {
       if (!isEmpty() && isBoiled()) {
           // 排出煮沸的巧克力和牛奶
           empty = true;
       }
    }

    public void boil() {
        if (!isEmpty() && !isBoiled()) {
            //将炉内物煮沸
            boiled = true;
        }
    }

    public boolean isEmpty() {
        return empty;
    }

    public boolean isBoiled() {
        return boiled;
    }

}
